<template>
  <div class="raterItem_wrapper">
    <div class="top">
      <div class="title">{{ raterSort }}.{{ raterTitle }}</div>
      <div class="rate">{{ rateNum }}分</div>
    </div>
    <div class="range-box" @click="clickRange">
      <range
        v-model="rateNum"
        :max="10"
        :min="1"
        @on-change="onChange"
      ></range>

    </div>
  </div>
</template>

<script>
import { Range } from "vux";

export default {
  name: "rater",
  props: {
    raterTitle: String,
    raterSort: Number,
    isRateShow: Boolean,
    raterCurrent: Number,
    sortNum:null
  },
  components: {
    Range
  },

  mounted() {
    this.rateShow = this.isRateShow;
    this.sendObj.No = this.raterSort;
  },
  data() {
    return {
      rateNum: 1,
      rateShow: false,
      current: null,
      sendObj: {},
      scoreList: [-5, -3, 0, 3, 5],
    };
  },
  methods: {
    clickRange(e) { 
      let moveX = e.pageX * 0.02;
      if (moveX < 0.6) {
        this.rateNum = 1;
      } else if (moveX > 0.6 && moveX < 1.23) {
        this.rateNum = 1;
      } else if (moveX > 1.23 && moveX < 1.86) {
        this.rateNum = 2;
      } else if (moveX > 1.86 && moveX < 2.49) {
        this.rateNum = 3;
      } else if (moveX > 2.49 && moveX < 3.12) {
        this.rateNum = 4;
      } else if (moveX > 3.12 && moveX < 3.75) {
        this.rateNum = 5;
      } else if (moveX > 3.75 && moveX < 4.38) {
        this.rateNum = 6;
      } else if (moveX > 4.38 && moveX < 5.01) {
        this.rateNum = 7;
      } else if (moveX > 5.01 && moveX < 5.64) {
        this.rateNum = 8;
      } else if (moveX > 5.64 && moveX < 6.24) {
        this.rateNum = 9;
      } else if (moveX > 6.24 && moveX < 6.87) {
        this.rateNum = 10;
      } else if (moveX > 6.87 && moveX < 7.5) {
        this.rateNum = 10;
      }
      this.sendObj.sort = this.rateNum ;
      this.$emit("sort", this.sendObj);
    },
    onChange(e) {
      this.sendObj.sort = e ;
      this.$emit("sort", this.sendObj);
    },

    handleClick(e, num) {
      this.rateNum = num;
      this.current = num;
      if (!this.rateShow) this.rateShow = true;
      this.sendObj.sort = num;
      this.$emit("sort", this.sendObj);
    }
  }
};
</script>

<style lang="less">
.raterItem_wrapper {
  width: 100%;
  background: #fff;
  padding: 0.3rem 0.3rem 0.2rem;
  .top {
    display: flex;
    justify-content: space-between;
    font-size: 0.3rem;
    font-weight: bold;
    margin-bottom: 0.4rem;
    .title {
      color: #222;
    }
    .rate {
      color: #bbb;
    }
  }
  .range-box {
    position: relative;
    padding: 0 0.3rem;
    margin-top: 0.15rem;
    .vux-range-input-box {
      padding: 0 0.3rem;
      margin: 0 !important;
    }
    .range-bar {
      height: 0.16rem !important;
      .range-quantity {
        background-color: @secondColor;
        border-radius: 0.08rem;
      }
      .range-handle {
        width: 0.32rem;
        height: 0.32rem;
        top: -0.08rem !important;
        -webkit-box-shadow: 0 1px 3px @secondColor;
        box-shadow: 0 1px 3px @secondColor;
      }
     .range-min {
        text-align: left;
      }
      .range-max{
        color: @mainColor
      }
    }
  }
}
</style>

